package com.aop;

import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author: cxt
 * @time: 2022/11/7
 * 中间商类(代理类)
 */
public class Middleman<T> implements InvocationHandler, Serializable {

    private T target;

    public Middleman(T target) {
        this.target = target;
    }

    /**
     * proxy:代表动态代理对象
     * method：代表正在执行的方法
     * args：代表调用目标方法时传入的实参
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("中间商找厂家低价拿货……");
        Object result = method.invoke(target, args);
        return result;
    }

    @Override
    public String toString() {
        return "Middleman{" +
                "target=" + target +
                '}';
    }
}
